<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->team_status;
$tabs=array(
	array('op'=>'list','query'=>'status=100','title'=>'全部拼单'),
	array('op'=>'list','query'=>'status=0','title'=>'拼单中'),
	array('op'=>'list','query'=>'status=1','title'=>'拼单成功'),
	array('op'=>'list','query'=>'status=2','title'=>'拼单失败'),
); 
if($_RQ['op']=='list'){
	$return['params']=array('plugin_name'=>'jy_pingdd_pin');
	$params=array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_pingdd_pin');
	if($_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
	}
	if(!empty($_RQ['goodstitle'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['goodstitle']).'%';
		$goodsids=pdo_getall('jy_weishop_goods',$params2,'id','id');
		if($goodsids){
			$goodsids=array_keys($goodsids);
			$params['goodsid']=$goodsids;
		}
		$return['params']['goodstitle']=$_RQ['goodstitle'];
	}
	$return['params']['status']=intval($_RQ['status']);
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_weishop_groups_team',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if($item['goods']['groupprice']==0){
				$return['pluginset']['groupdiscount']=$return['pluginset']['groupdiscount']?:98;
				$item['goods']['groupprice'] =$item['goods']['price']*$return['pluginset']['groupdiscount']/100;
			}
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['order']=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_pingdd_pin','teamid'=>$item['id'],'mid'=>$item['mid']));
			$item['member']=cfc('core')->member_show($item['mid']);
			//到期时间
			$goods=$this->model('model')->up_price($item['goods'],$return['pluginset'],true);
			$item['endtime']=$goods['grouptime']*60*60+$item['createtime'];
			$item['goodstitle']=$item['goods']['title'];
			$item['groupnum']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_pingdd_pin','status'=>array(1,2,3,5,6,7,10),'teamid'=>$item['id']));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：<red>【每人每天最多中次数】设置后，就算拼中人数==成团人数，或者拼中人数不满设置的【拼中人数】，该客户依然无法拼中，会显示拼单失败！注意这不是BUG</red>','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'拼ID','type'=>'string'),
			array('name'=>'member','title'=>'拼长信息_Member','type'=>'member'),
			array('name'=>'groupnum','title'=>'参与人数','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'time'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_pingdd_pin/order//status=1','title'=>'拼中人','show'=>array('status'=>1)),
			array('type'=>'href','action'=>'jy_pingdd_pin/order//status=5','title'=>'失败人','show'=>array('status'=>1)),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
